import java.util.ArrayList;
import java.util.List;

public class Solution916 {
    public List<String> wordSubsets(String[] words1, String[] words2) {
        int[] f=new int[26];
        List<String> list=new ArrayList<>();
        for (String s : words2) {
            int[] g=new int[26];
            for (char c : s.toCharArray()) {
                g[c-'a']++;
            }
            for (int i = 0; i < 26; i++) {
                f[i]=Math.max(f[i],g[i]);
            }
        }
        for (String s : words1) {
            int[] g=new int[26];
            for (char c : s.toCharArray()) {
                g[c-'a']++;
            }
            boolean flag=true;
            for (int i = 0; i < 26; i++) {
                if (g[i]<f[i]){
                    flag=false;
                    break;
                }
            }
            if (flag){
                list.add(s);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(new Solution916().wordSubsets(new String[]{"amazon","apple","facebook","google","leetcode"},new String[]{"e","o"}));
    }
}
